﻿using DTcms.Common;
using DTcms.Web.Mvc.UI;
using System.Web.Http;

namespace DTcms.Web.Plugin.Controllers
{
    public class linkController : WebApiController
    {
        #region 添加友情链接================================
        [HttpPost]
        public IHttpActionResult add(int site, string txtVerCode, string TxtName, string TxtEmail, string TxtQQ, string TxtUserName, string TxtTel, string TxtUrl, string TxtMsg, string img_url)
        {
            BLL.plugin_link bll = new BLL.plugin_link();
            Model.plugin_link model = new Model.plugin_link();

            //检查站点目录
            if (site == 0)
            {
                return Json(new { status = 0, msg = "对不起，网站传输参数有误！" });
            }
            string result1 = verify_code(txtVerCode);
            if (result1 != "success")
            {
                return Json(new { status = 0, msg = result1 });
            }
            if (string.IsNullOrEmpty(TxtName))
            {
                return Json(new { status = 0, msg = "对不起，请输入网站标题！" });
            }
            if (string.IsNullOrEmpty(TxtUrl))
            {
                return Json(new { status = 0, msg = "对不起，请输入网站网址！" });
            }
            model.site_id = site;
            model.title = TxtName;
            model.is_lock = 1;
            model.is_red = 0;
            if (userModel != null)
            {
                model.user_name = userModel.user_name;
                model.user_tel = userModel.mobile;
            }
            else
            {
                model.user_tel = TxtTel;
            }
            model.email = Utils.DropHTML(TxtEmail);
            model.site_url = Utils.DropHTML(TxtUrl);
            model.img_url = Utils.DropHTML(img_url);
            model.email = TxtEmail;
            model.is_image = 1;
            model.content = TxtMsg;
            if (string.IsNullOrEmpty(model.img_url))
            {
                model.is_image = 0;
            }
            if (bll.Add(model) > 0)
            {
                return Json(new { status = 1, msg = "恭喜您，提交成功！" });
            }
            return Json(new { status = 0, msg = "对不起，保存过程中发生错误！" });
        }
        #endregion
    }
}